package com.ai3d.rfid.base.activity

import android.os.Bundle
import android.view.View
import androidx.databinding.ViewDataBinding
import com.ai3d.rfid.base.vm.BaseViewModel
import com.ai3d.rfid.ext.dismissLoadingExt
import com.ai3d.rfid.ext.inflateBindingWithGeneric
import com.ai3d.rfid.ext.showLoadingExt

/**
 *Base activity injected with ViewModel and ViewDataBinding,
 * which is suited to someone who wants to use ViewDataBinding
 */
abstract class BaseVmVdbActivity<VM : BaseViewModel, VDB : ViewDataBinding> : BaseVmActivity<VM>() {

    override fun layoutId() = 0

    lateinit var mDatabind: VDB

    /**
     *  DataBinding creation and return the root of it
     */
    override fun initDataBind(): View? {
        mDatabind = inflateBindingWithGeneric(layoutInflater)
        return mDatabind.root
    }

    abstract override fun initView(savedInstanceState: Bundle?)

    /**
     * creation of LiveData observer
     */
    override fun createObserver() {}

    /**
     * show loading dialog
     */
    override fun showLoading(message: String) {
        showLoadingExt(message)
    }

    /**
     * dismiss loading dialog
     */
    override fun dismissLoading() {
        dismissLoadingExt()
    }

    /**
     *in any cases that the adjusted layout incidentally corrupted ,
     * what u only need to do is overriding this fun
     */
    /* override fun getResources(): Resources {
         AutoSizeCompat.autoConvertDensityOfGlobal(super.getResources())
         return super.getResources()
     }*/
}